package com.yytek.upgrade.controller;

import java.util.List;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.upgrade.domain.UpgradeFirmware;
import com.yytek.upgrade.service.IUpgradeFirmwareService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 升级包Controller
 * 
 * @author yytek-iot
 * @date 2022-09-06
 */
@Api(value = "升级包控制器", tags = {"升级包管理"})
@RestController
@RequestMapping("/firmware")
public class UpgradeFirmwareController extends BaseController
{
    @Autowired
    private IUpgradeFirmwareService upgradeFirmwareService;

    /**
     * 分页查询升级包列表
     */
    @ApiOperation("分页查询升级包列表")
    @RequiresPermissions("upgrade:firmware:list")
    @GetMapping("/list")
    public TableDataInfo list(UpgradeFirmware upgradeFirmware)
    {
        startPage();
        List<UpgradeFirmware> list = upgradeFirmwareService.selectUpgradeFirmwareList(upgradeFirmware);
        return getDataTable(list);
    }

    /**
     * 导出升级包列表
     */
    @ApiOperation("导出升级包列表")
    @RequiresPermissions("upgrade:firmware:export")
    @Log(title = "升级包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UpgradeFirmware upgradeFirmware)
    {
        List<UpgradeFirmware> list = upgradeFirmwareService.selectUpgradeFirmwareList(upgradeFirmware);
        ExcelUtil<UpgradeFirmware> util = new ExcelUtil<UpgradeFirmware>(UpgradeFirmware.class);
        util.exportExcel(response, list, "升级包数据");
    }

    /**
     * 获取升级包详细信息
     */
    @ApiOperation("获取升级包详细信息")
    @RequiresPermissions("upgrade:firmware:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(upgradeFirmwareService.selectUpgradeFirmwareById(id));
    }

    /**
     * 新增升级包
     */
    @ApiOperation("新增升级包")
    @RequiresPermissions("upgrade:firmware:add")
    @Log(title = "升级包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UpgradeFirmware upgradeFirmware)
    {
        return toAjax(upgradeFirmwareService.insertUpgradeFirmware(upgradeFirmware));
    }

    /**
     * 修改升级包
     */
    @ApiOperation("修改升级包")
    @RequiresPermissions("upgrade:firmware:edit")
    @Log(title = "升级包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UpgradeFirmware upgradeFirmware)
    {
        return toAjax(upgradeFirmwareService.updateUpgradeFirmware(upgradeFirmware));
    }

    /**
     * 删除升级包
     */
    @ApiOperation("删除升级包")
    @RequiresPermissions("upgrade:firmware:remove")
    @Log(title = "升级包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(upgradeFirmwareService.deleteUpgradeFirmwareByIds(ids));
    }
}
